package mysql

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId  int     `gorm:"type:int;comment:用户id"`
	ClassId int     `gorm:"type:int;comment:课程商品id"`
	CarId   int     `gorm:"type:int;comment:购物车id"`
	OrderSn string  `gorm:"type:varchar(100);unique;comment:订单编号"`
	Name    string  `gorm:"type:varchar(20);comment:课程名称"`
	Price   float64 `gorm:"type:decimal(10,2);comment:课程价格"`
	Num     int     `gorm:"type:int;comment:数量"`
	Amount  float64 `gorm:"type:decimal(10,2);comment:实付价格"`
	Types   int     `gorm:"type:int;default:1;comment:订单状态(1-待支付，2-支付失败，取消订单，3-支付成功)"`
}

func (Order) TableName() string {
	return "order"
}

func (o *Order) AddOrder() error {
	return DB.Create(&o).Error
}

func (o *Order) UpdatedOrder(sn string) error {
	return DB.Where("order_sn=?", sn).Find(&o).Update("types", 2).Error
}
